package com.isdepci.project.carbon.controller;

import com.isdepci.common.utils.poi.ExcelUtil;
import com.isdepci.framework.aspectj.lang.annotation.Log;
import com.isdepci.framework.aspectj.lang.enums.BusinessType;
import com.isdepci.framework.web.controller.BaseController;
import com.isdepci.framework.web.domain.AjaxResult;
import com.isdepci.framework.web.page.TableDataInfo;
import com.isdepci.project.carbon.domain.CcerProject;
import com.isdepci.project.carbon.service.ICcerProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * CCER项目Controller
 *
 * @author isdepci
 * @date 2023-05-15
 */
@RestController
@RequestMapping("/ccer/list")
public class CcerProjectController extends BaseController {

    @Autowired
    private ICcerProjectService projectListService;

    @GetMapping("/dict")
    public AjaxResult selectCCERDict(){
        List<CcerProject> list = projectListService.selectCCERDict();
        return AjaxResult.success(list);
    }


    /**
     * 查询CCER项目列表
     */
    @PreAuthorize("@ss.hasPermi('ccer:list:list')")
    @GetMapping("/list")
    public TableDataInfo list(CcerProject ccerProject){
        startPage();
        List<CcerProject> list = projectListService.selectProjectListList(ccerProject);
        return getDataTable(list);
    }


    /**
     * 查询CCER项目名称
     */
    @PreAuthorize("@ss.hasPermi('ccer:list:list')")
    @GetMapping("/nameList")
    public TableDataInfo nameList(CcerProject ccerProject){
        startPage();
        List<CcerProject> list = projectListService.selectProjectListNameList(ccerProject);
        return getDataTable(list);
    }



    /**
     * 获取CCER项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('ccer:list:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(projectListService.selectProjectListById(id));
    }

    /**
     * 新增CCER项目
     */
    @PreAuthorize("@ss.hasPermi('ccer:list:addCCER')")
    @Log(title = "CCER项目", businessType = BusinessType.INSERT)
    @PostMapping("/addCCER")
    public AjaxResult add(@RequestBody CcerProject ccerProject){
        return toAjax(projectListService.insertProjectList(ccerProject));
    }

    /**
     * 修改CCER项目
     */
    @PreAuthorize("@ss.hasPermi('ccer:list:editCCER')")
    @Log(title = "CCER项目", businessType = BusinessType.UPDATE)
    @PutMapping("/editCCER")
    public AjaxResult edit(@RequestBody CcerProject ccerProject){
        return toAjax(projectListService.updateProjectList(ccerProject));
    }

    /**
     * 删除CCER项目
     */
    @PreAuthorize("@ss.hasPermi('ccer:list:remove')")
    @Log(title = "CCER项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids){
        return toAjax(projectListService.deleteProjectListByIds(ids));
    }




    /**
     * 导出CCER项目列表
     */
    @PreAuthorize("@ss.hasPermi('ccer:list:export')")
    @Log(title = "CCER项目", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CcerProject ccerProject){
        List<CcerProject> list = projectListService.selectProjectListList(ccerProject);
        ExcelUtil<CcerProject> util = new ExcelUtil<CcerProject>(CcerProject.class);
        return util.exportExcel(list, "list");
    }
}
